/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.runtime.control
{
    import mx.containers.Canvas;
    import mx.controls.Image;
    import mx.controls.Label;
    import mx.controls.dataGridClasses.DataGridListData;
    import mx.controls.listClasses.BaseListData;
    import mx.controls.listClasses.IDropInListItemRenderer;
    import mx.managers.IFocusManagerComponent;
	/**
	 * EDIDataGrid中显示文本的控件
	 * 
	 */    
	public class TextItemRenender extends Canvas implements IDropInListItemRenderer,IFocusManagerComponent
	{
		private var _listData:DataGridListData;
		private var _data:Object;
		private var _text:String;
		private var oLabel:Label;
		public var value:String;
		public var dataProvider:XMLList;
		/**
		 * 
		 * 构造函数
		 */		
		public function TextItemRenender() 
		{
            super();
            oLabel=new Label();
            oLabel.percentHeight=100;
            oLabel.percentWidth=100;
            this.horizontalScrollPolicy="off";
            this.verticalScrollPolicy="off";
            this.addChild(oLabel);
		}
        /**
         * 复写 get data 获取数据函数
         * @return 
         * 
         */		
        override public function get data():Object
		{
		    return _data;
		}
		
		/**
		 * 复写获取数据函数，判断数据是否有效
		 * @param value
		 * 
		 */
		override public function set data(value:Object):void
		{
		    var newText:String;
		    var str:String;
		    _data = value;
		    if (_data is XML)
		    {
		    	for each(var item:XML in XML(_data).children())
		    	{
		    		if(item.localName()==_listData.dataField)
		    		{
		    			if(dataProvider)
		    			{
		    				if(dataProvider.(@key==item.toString())[0])
			    			{
			    				oLabel.text=String(dataProvider.(@key==item.toString())[0].@value);
			    			}
		    			}
		    			else
		    			{
		    				oLabel.text=item.toString();
		    			}
		    			break;
		    		}
		    	}
		    	if(oLabel.text=="")
			    {
			    	oLabel.text=String(_data[_listData.dataField]);
			    }
		    }
		    
		}
        /**
         * 在EDIDataGrid列表中的数据,包括行列位置信息等
         * @return 
         * 
         */        
        public function get listData():BaseListData
		{
		    return _listData;
		}
		/**
		 * 在EDIDataGrid列表中的数据,包括行列位置信息等
		 * @param value
		 * 
		 */
		public function set listData(value:BaseListData):void
		{
		    _listData = DataGridListData(value);
		} 
	}
}